package com.king.pages.novel.entity;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.ArrayList;
import java.util.List;

import com.king.db.annotation.Column;
import com.king.db.annotation.NColumn;
import com.king.db.annotation.Table;
import com.king.mind.ChapterNode;

import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

/**
 * 章节
 */
@Getter
@Setter
@ToString
@Table("novel_chapter")
public class Chapter {

	private String id;

	@Column("novel_volume_id")
	private String novelVolumeId;

	private String title;

	@Column("create_date")
	private LocalDateTime createDate;

	private String word;

	private String description;

	private int num;

	@Column("novel_id")
	private String novelId;

	@NColumn
	private String[] labels;

	public ChapterNode toNode() {
		ChapterNode n = new ChapterNode();
		n.setId(this.id);
		n.setTitle(String.format("第 %s 章 %s", this.num, this.title));
		n.setSubTitle(String.format("字数：%s，创建于：%s", word == null ? 0 : word.length(),
				createDate.format(DateTimeFormatter.ofPattern("yyyy年MM月dd日"))));
		n.setLabels(labels);
		return n;
	}

	/**
	 * 获取labels
	 * 
	 * @return
	 * @author king
	 * @date 2025年7月22日-10:06:48
	 */
	public List<ChapterLabel> labels() {
		if (this.labels == null) {
			return null;
		}
		List<ChapterLabel> r = new ArrayList<>();
		ChapterLabel c;
		for (String l : labels) {
			c = new ChapterLabel();
			c.setChapterId(this.id);
			c.setText(l);
			r.add(c);
		}
		return r;
	}

}
